package com.zhuiYun.project.api.trend.mapper;

import com.zhuiYun.project.api.trend.entity.TrendComment;
import com.zhuiYun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @Author gpd
* @Description 动态评论mapper
* @Date 2023-04-17 下午 04:41
* @Return

*/

@Mapper
public interface TrendCommentMapper extends BaseMapper<TrendComment> {
    @Select("SELECT\n" +
            "\tc.*,\n" +
            "\t( CASE WHEN ( t.id IS NULL OR t.id = '' ) THEN '0' ELSE 1 END ) AS flag \n" +
            "FROM\n" +
            "\ttrend_comment c\n" +
            "\tLEFT JOIN ( SELECT * FROM trend_comment_thumb tt WHERE tt.user_id = #{userId} ) t ON c.id = t.tc_id\n" +
            "\tLEFT JOIN trend_content tc ON tc.id = c.trend_id \n" +
            "WHERE\n" +
            "\tc.del_flag = 0 \n" +
            "\tAND c.trend_id = #{trendId}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "thumbFlag" , column = "flag")
    })
    List<TrendComment> getUserTrend(Integer userId, Integer trendId);

    @Update("update  trend_comment set  likes = likes + 1 where id=#{tId}")
    //将对应的评论点赞数加1（uniapp 动态内容评论点赞）
    void thumbsCommentUpState(Integer tId);

    @Update("update  trend_comment set  likes = likes - 1 where id=#{tcId}")
    // 将对应的评论点赞数减一(uniapp 动态内容评论取消点赞）
    void noThumbsCommentUpState(Integer tcId);
}
